package com.asset.modules.system.service.impl;


import com.asset.modules.system.mapper.ProjectMapper;
import com.asset.modules.system.model.Project;
import com.asset.modules.system.service.ProjectService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author asset
 * @since 2020-08-13
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {

    /**
     * 根据公司编码获取项目列表
     * @param companyCode
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public List<Project> getProjectsByCompanyCode(String companyCode){
        QueryWrapper<Project> qw  = new QueryWrapper<>();
        qw.eq("company_code", companyCode);
        return list(qw);
    }

    /**
     * 根据项目名称获取项目
     * @param name
     * @return
     */
    @Override
    public Project getProjectByName(String name) {
        QueryWrapper<Project> qw  = new QueryWrapper<>();
        qw.eq("project_name", name);
        return getOne(qw);
    }

    @Override
    public List<String> removeByIdsWithChecking(List<? extends Collection> ids) {
        return null;
    }


    @Override
    public List<Project> getProjectsByCompanyId(String id) {
        QueryWrapper<Project> qw = new QueryWrapper<>();
        qw.eq("company_id", id);
        return list(qw);
    }

    @Override
    public boolean isExist(String column, String name) {
        QueryWrapper<Project> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(column, name);
        List result = list(queryWrapper);
        if(result.size()>0){
            return true;
        }
        return false;
    }
}
